Page({
  /**
   * 页面的初始数据
   */
  data: {
    lists: [] as string | Record<string, any> | ArrayBuffer,
    newsong: [],
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
    var that = this;
    wx.request({
      url: "http://localhost:3000/top/playlist/highquality",
      success: function (res) {
        // console.log(res.data.playlists);
        that.setData({
          lists: (res.data as any).playlists
            .sort(() => {
              return Math.random() - 0.5;
            })
            .slice(0, 6),
        });
      },
    });
    wx.request({
      url: "http://localhost:3000/personalized/newsong",
      success: function (res) {
        // console.log(res.data.result);
        that.setData({
          newsong: (res.data as any).result,
        });
      },
    });
  },

  /* 编辑推荐跳转详情页 */
  toEdit(e: any) {
    // console.log("--", e.currentTarget.dataset.itemId);
    let editInfo = e.currentTarget.dataset.itemId;
    wx.navigateTo({
      url: "/pages/editDetails/editDetails?ids=" + editInfo,
    });
  },
  /* 最新音乐跳转详情页 */
  toLatest(e: any) {
    // console.log("--", e.currentTarget.dataset.itemId);
    let latest = e.currentTarget.dataset.itemId;
    wx.navigateTo({
      url: "/pages/newsongDetails/newsongDetails?newId=" + latest,
    });
  },
});
